import { Application } from "@pixi/app";
import { Filter, Point, Texture } from "@pixi/core";
import { Sprite } from "@pixi/sprite";
import vertexShader from './vertex.glsl?raw'
import fragmentShader from './fragment.glsl?raw'

export async function initFilter(app: Application) {
  //   let texture = await Texture.fromURL('https://p5.music.126.net/obj/wo3DlcOGw6DClTvDisK1/44264609950/d06d/fb6f/a80b/ea3d8e03cecfd3d96dabff74a659e1ae.png')
  let texture = await Texture.fromURL('https://p5.music.126.net/obj/wonDlsKUwrLClGjCm8Kx/44560405277/cfdc/3f35/8b92/d4472d33b5826c5bc9e31b0b2b355bf9.jpg');

  let sp = Sprite.from(texture);
  sp.x = 300;
  sp.y = 400;
  sp.width = 187.5;
  sp.height = 211;

  let f = new Filter(vertexShader, fragmentShader, {
    uDimensions: [sp.width * 2, sp.height, 1 / (sp.width * 2), 1 / sp.height],
    uVideoSampler: texture.baseTexture,
    uPoint: sp.toGlobal(new Point(0, 0))
  })
  f.resolution = 2;

  sp.filters = [f]

  app.stage.addChild(sp);
}